package stu.aistar.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import stu.aistar.model.pojo.MovieAllTypes;
import stu.aistar.model.pojo.MovieType;

import java.util.List;
@Component
public interface MovieTypeMapper {
    List<MovieType> findMovieTypeByIds(@Param("ids")String[] ids);

    @Select("select *from movietype")
    List<MovieType> findAll();

    @Select("select count(*) from movietype")
    Integer findTotal();

    @Select("select * from movietype where type_name = #{typeName}")
    MovieType findMovieTypeByName(@Param("typeName") String name);

    @Insert("insert into movietype(type_name) values (#{typeName}) ")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    Integer insertMovieType(@Param("typeName") String name);

    @Update("update movietype set type_name = #{typeName} where id =#{id}")
    Integer updateTypeById(MovieType movieType);

    @Delete("delete from movietype where type_name = #{name}")
    Integer deleteTypeByName(@Param("name")String name);

    @Select("select *from movie_all_types where movie_id = #{movieId}")
    MovieAllTypes findMovieTypes(@Param("movieId") Integer id);

    @Insert("Insert into movie_all_types(movie_id,type_ids) values(#{movieId},#{ids})")
    Integer insertMovieTypes(@Param("ids")String ids,@Param("movieId")Integer movieId);

    @Update("update movie_all_types set type_ids = #{ids} where movie_id = #{movieId}")
    Integer updateMovieTypes(@Param("ids")String ids,@Param("movieId")Integer movieId);
}
